package com.example.tests;

import java.util.Collections;
import java.util.List;
import org.junit.*;
import static org.junit.Assert.*;
import com.example.pages.ManagementPage;

public class CreateAndDeleteUser extends TestBase {

	@Test
	public void testCreateUser() throws Exception {
		ManagementPage managementPage = goToMainPage()
			.loginAs("admin", "adm")
			.goToManagementPage();
		List<User> oldUserList = managementPage.getUsers();
		User user = new User()
			.withName("user1").withEmail("user1@test.com").withPassword("test");
		if (oldUserList.contains(user)) {
			managementPage.deleteUser(user);
			oldUserList = managementPage.getUsers();
		}
		managementPage.createUser(user);
		List<User> newUserList = managementPage.getUsers();
		oldUserList.add(user);
		Collections.sort(oldUserList);
		assertEquals(oldUserList, newUserList);
	}
	
	@Test
	public void testDeleteUser() throws Exception {
		ManagementPage managementPage = goToMainPage()
			.loginAs("admin", "adm")
			.goToManagementPage();
		List<User> oldUserList = managementPage.getUsers();
		managementPage.deleteAnyUser();
		List<User> newUserList = managementPage.getUsers();
		//Collections.sort(oldUserList);
		assertFalse(oldUserList.equals(newUserList));
	}
}
